package st.business.tepth.business.businfo;

import android.support.annotation.Nullable;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.List;

import st.business.tepth.R;
import st.business.tepth.base.OnItemChooseListener;
import st.business.tepth.business.bean.NumberBean;

/**
 * @author zhangyu
 * @date 2019/2/28
 */
public class FooterNumberAdapter extends BaseQuickAdapter<NumberBean, BaseViewHolder> {
    private int mOldPosition = 0;
    private OnItemChooseListener<NumberBean> mListener;
    public FooterNumberAdapter(int layoutResId,
                               @Nullable List<NumberBean> data,
                               OnItemChooseListener<NumberBean> listener) {
        super(layoutResId, data);
        mListener = listener;
    }

    @Override
    protected void convert(final BaseViewHolder helper, final NumberBean item) {
        helper.setText(R.id.tv_number,item.getNumber()+"");
        if(item.isChecked()){
            helper.setBackgroundRes(R.id.tv_number, R.drawable
                    .shape_number_indicator_p);
        }else{
            helper.setBackgroundRes(R.id.tv_number, R.drawable
                    .shape_number_indicator_n);
        }
        helper.getView(R.id.tv_number).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                item.setChecked(true);
                helper.setBackgroundRes(R.id.tv_number, R.drawable
                        .shape_number_indicator_p);
                if(mOldPosition != helper.getAdapterPosition()){
                    NumberBean oldBean = getItem(mOldPosition);
                    if(oldBean != null){
                        oldBean.setChecked(false);
                        notifyItemChanged(mOldPosition);
                    }
                    mOldPosition = helper.getAdapterPosition();
                }
                if(mListener != null){
                    mListener.onChoose(item);
                }
                // move(helper.getAdapterPosition());
//                if(helper.getAdapterPosition() >= getItemCount()-4){
//                    mIvRight.setEnabled(false);
//                    mIvRight.setBackgroundResource(R.drawable.ic_indicator_right_un_enable);
//                    mIvLeft.setEnabled(true);
//                    mIvLeft.setBackgroundResource(R.drawable.selector_left_number_indicator);
//                }else if(helper.getAdapterPosition() <4){
//                    mIvLeft.setEnabled(false);
//                    mIvLeft.setBackgroundResource(R.drawable.ic_indicator_left_un_enable);
//                    mIvRight.setEnabled(true);
//                    mIvRight.setBackgroundResource(R.drawable.selector_right_number_indicator);
//                }else{
//                    mIvRight.setEnabled(true);
//                    mIvRight.setBackgroundResource(R.drawable.selector_right_number_indicator);
//                    mIvLeft.setEnabled(true);
//                    mIvLeft.setBackgroundResource(R.drawable.selector_left_number_indicator);
//                }
//                mTvCount.setText(String.format(Locale.CHINA,
//                        "%d/%d", helper.getAdapterPosition() + 1, list.size()));
//                scrollHelper.scrollToPosition(helper.getAdapterPosition());
            }

        });
    }
}
